package com.webank.maling.analyzer.java.strategy.impl;

import com.webank.maling.analyzer.java.strategy.NodeContentStrategy;
import com.webank.maling.base.model.Node;
import com.webank.maling.base.model.RpcInterfaceNode;
import lombok.extern.slf4j.Slf4j;
import spoon.reflect.factory.Factory;

/**
 * RPC接口节点内容策略
 */
@Slf4j
public class RpcInterfaceNodeStrategy implements NodeContentStrategy {

    @Override
    public String getDigest(Node node, Object context) {
        if (node instanceof RpcInterfaceNode) {
            RpcInterfaceNode rpcNode = (RpcInterfaceNode) node;
            StringBuilder content = new StringBuilder();
            
            content.append("RPC Interface: ").append(rpcNode.getInterfaceName()).append("#").append(rpcNode.getMethodName()).append("\n");
            content.append("Topic: ").append(rpcNode.getTopic()).append("\n");
            content.append("Project Q: ").append(rpcNode.getProjectQ()).append("\n");
            content.append("Protocol: ").append(rpcNode.getProtocol()).append("\n");
            content.append("Topic Mode: ").append(rpcNode.getTopicMode()).append("\n");
            
            if (rpcNode.getContent() != null) {
                content.append("Content: ").append(rpcNode.getContent());
            }
            
            return content.toString();
        }
        
        log.warn("Node is not RpcInterfaceNode: {}", node.getClass().getSimpleName());
        return node.getContent() != null ? node.getContent() : "";
    }
} 